home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Tools & Apps / OS⁄Toolbox / Apple Events / AE Word Services 1.0d6 / Writeswell Jr. Source / AEObj.c next >
Encoding:
C/C++ Source or Header  |  1992-04-23  |  4.5 KB  |  187 lines  |  [TEXT/KAHL]

  1. /* AEObj.c
  2.  * Utilities for dealing with Apple Event Objects (making descriptors, etc.)
  3.  * ©1992 Working Software, Inc.
  4.  * This source code is copyrighted.  Permission is granted to use the Word Services
  5.  * portion of the Writeswell Jr. source code in your own programs, but you 
  6.  * may not distribute the Writeswell Jr. word-processor code as a 
  7.  * commercial product.  If you modify the code, please do not call it 
  8.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  9.  * program and don’t have to deal with a number of different versions with 
  10.  * who-knows-what going on in the code.
  11.  * 
  12.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  13.  * 18 Dec 91 Mike Crawford
  14.  */
  15.  
  16. #include <AppleEvents.h>
  17. #include <AEObjects.h>
  18. #include <AERegistry.h>
  19. #include "TBConstants.h"
  20. #include "TBGlobals.h"
  21. #include "AEObj.h"
  22. #include "ObWind.h"
  23. #include "ObText.h"
  24. #include "Gripe.h"
  25.  
  26. OSErr InstallMyAccessors( void );
  27. pascal OSErr MyCountProc(DescType desiredType,
  28.                         DescType containerClass,
  29.                         const AEDesc *container,
  30.                         long *result);
  31. pascal OSErr MyDisposeTokenProc(AEDesc *unneededToken);
  32. OSErr InstallMyCoercers( void );
  33.  
  34. OSErr InitAEObjStuff( void )
  35. {
  36.     OSErr err;
  37.     
  38.     err = AEObjectInit();
  39.     if ( err ){
  40.         Gripe( "\pAEObjectInit failed" );
  41.         return err;
  42.     }
  43.     
  44.     err = InstallMyAccessors();
  45.     if ( err ){
  46.         Gripe( "\pInstallMyAccessors failed" );
  47.         return err;
  48.     }
  49.  
  50.     /* Install the callback functions used by the AEObj parser */
  51.     err = AESetObjectCallbacks((compareProcPtr)nil, 
  52.             (countProcPtr)MyCountProc, 
  53.             (disposeTokenProcPtr)MyDisposeTokenProc,
  54.             (getMarkTokenProcPtr)nil,
  55.             (markProcPtr)nil, 
  56.             (adjustMarksProcPtr)nil, 
  57.             (getErrDescProcPtr)nil);
  58.     
  59.     err = InstallMyCoercers();
  60.     if ( err ){
  61.         Gripe( "\pInstallMyCoercers failed" );
  62.         return err;
  63.     }
  64.  
  65.     return noErr;
  66. }
  67.  
  68. OSErr InstallMyAccessors( void )
  69. {
  70.     OSErr err;
  71.     
  72.     /* We install the accessors to get various objects from various containers */
  73.     
  74.     /* Get a Window element from an application (null) container */
  75.     err = AEInstallObjectAccessor(cWindow,
  76.                                 typeNull,
  77.                                 (accessorProcPtr)WindFromNull,
  78.                                 0,
  79.                                 false);
  80.  
  81.     /* Get any property from a window container */
  82.     err = AEInstallObjectAccessor( typeProperty,
  83.                                 cWindow,
  84.                                 (accessorProcPtr)PropFromWind,
  85.                                 0,
  86.                                 false);
  87.  
  88.     /* Get text from a window container */
  89.     err = AEInstallObjectAccessor( cText,
  90.                                 cWindow,
  91.                                 (accessorProcPtr)TextFromWind,
  92.                                 0,
  93.                                 false);
  94.  
  95.     /* Get a word from a TextEdit text container */
  96.     err = AEInstallObjectAccessor( cWord,
  97.                                 typeTEText,
  98.                                 (accessorProcPtr)WordFromTEText,
  99.                                 0,
  100.                                 false);
  101.  
  102.     /* Get a char (or set thereof) from a TextEdit text container */
  103.     err = AEInstallObjectAccessor( cChar,
  104.                                 typeTEText,
  105.                                 (accessorProcPtr)CharFromTEText,
  106.                                 0,
  107.                                 false);
  108.  
  109.     /* Get any property from a text container */
  110.     err = AEInstallObjectAccessor( typeProperty,
  111.                                 typeTEText,
  112.                                 (accessorProcPtr)PropFromTEText,
  113.                                 0,
  114.                                 false);
  115.  
  116.     return noErr;
  117. }
  118.  
  119. OSErr InstallMyCoercers( void )
  120. {
  121.     OSErr err;
  122.  
  123.     err = AEInstallCoercionHandler( typeChar,
  124.                                     typePString,
  125.                                     (ProcPtr)TextPtrToPString,
  126.                                     0L,
  127.                                     false,        /* Pass a pointer not a descriptor */
  128.                                     false );    /* Application table, not System */
  129.     if ( err ){
  130.         Gripe( "\pAEInstallCoercionHandler failed on TextPtrToPString" );
  131.         return err;
  132.     }
  133.  
  134.     return noErr;
  135. }
  136.  
  137. /* This is a single routine that must know how to count each of the kinds of objects
  138.  * that are used in this application.  Eventually we should have it call functions
  139.  * that are in the ObjXXX files.
  140.  */
  141.  
  142. pascal OSErr MyCountProc(DescType desiredType,
  143.                         DescType containerClass,
  144.                         const AEDesc *container,
  145.                         long *result)
  146. {
  147.     OSErr err = noErr;
  148.     
  149.     switch ( desiredType ){
  150.         case cWindow:
  151.             *result = ( gDocWindow ? 1 : 0 );
  152.             break;
  153.         default:
  154.             Gripe( "\pTrying to count an object I do not know about" );
  155.             err = errAENoSuchObject;
  156.             break;
  157.     }
  158.     
  159.     return err;
  160. }
  161.  
  162. pascal OSErr MyDisposeTokenProc(AEDesc *unneededToken)
  163. {
  164.     OSErr myErr = noErr;
  165.  
  166.     /* In most cases we just toss out the token descriptor.  We may need to do more
  167.      * stuff in the event the the token handle actually points to some real data.
  168.      */
  169.  
  170.     switch (unneededToken->descriptorType) {
  171.         case cWindow:
  172.             myErr = AEDisposeDesc(unneededToken);
  173.             break;
  174.  
  175.         default:
  176.             /* I default to just disposing of the token, ne ces pa  */
  177.             AEDisposeDesc(unneededToken);
  178.             break;
  179.     }
  180.     return(myErr);
  181. }
  182.  
  183. OSErr MakeTextDesc( AEDesc *descPtr )
  184. {
  185.     
  186.     return noErr;
  187. }